import {Button} from 'antd';
import React, {useState, useRef, useEffect} from 'react';
import {PageContainer} from '@ant-design/pro-layout';
import ProTable from '@ant-design/pro-table';
import {getPage, exportRecord} from './service';
import {DownloadOutlined} from '@ant-design/icons';
import "./index.css";
import {saveFileAs} from "@/utils/utils";
const TableList = (props) => {
  const actionRef = useRef();
  const [count, setCount] = useState();
  useEffect(() => {

  }, []);
  const columns = [
    {
      title: '客户',
      dataIndex: 'name',
      hideInSearch: true,
    },
    {
      title: '电话',
      dataIndex: 'tel',
      hideInSearch: true,
    },
    {
      title: '归属人',
      dataIndex: 'belongName',
      hideInSearch: true,
    },
    {
      title: '归属人工号',
      dataIndex: 'belongNumber',
      hideInSearch: true,
    },
    {
      title: '归属店铺',
      dataIndex: 'belongStore',
      hideInSearch: true,
    },
  ];

  return (
    <PageContainer>
      <ProTable
        headerTitle="老模式客户列表"
        actionRef={actionRef}
        rowKey="id"
        search={{
          labelWidth: 120,
        }}
        scroll={{x: 1400}}
        bordered
        request={(params, sorter, filter) => getPage({...params, sorter, filter})}
        postData={(payload) => {
          const {list, total} = payload;
          setCount(total);
          return list || [];
        }}
        toolBarRender={() => [
          <Button
            key="newWarehouseBtn"
            type="primary"
            onClick={() => {
              exportRecord({type:'1'}).then(res=>{
                if (res){
                  saveFileAs(res, '老模式客户表');
                }
              })
            }}
          >
            <DownloadOutlined/> 导出
          </Button>
        ]}
        columns={columns}
        pagination={{
          defaultPageSize: 30,
          showSizeChanger: false,
          showTitle: false,
          total: count,
          showTotal: (total) => `共${total}条`,
        }}
      />
    </PageContainer>
  );
};

export default TableList;
